#ifndef __ATOMTRACE_HITRECORD_H_
#define __ATOMTRACE_HITRECORD_H_

#include "Vector3.h"
#include "atUtil.h"

namespace AtomTrace{

    typedef struct HitRecord
    {
        float t; // the closest hit
        int objID;
        int matID; // material ID
        int matIllum; // illumination identifier
        float transIndex;
        bool hitFront;
        
        bool normalComputed;
        
        Vector3 P; // hit point
        Vector3 N; // hit normal

        Vector3 e1;
        Vector3 e2; // triangle edge

        Vector3 incDir; // incoming ray direction
        Vector3 newDir; // new ray dir for reflection/refraction ray
        Vector3 snellRef; // snell's reflection for refractin effect

        HitRecord()
        {
            normalComputed = false;
        }
        
        inline void Init()
        {
            t = 10000000.0f;
            objID = -1;
            matID = -1;
            P.Set(0.0f, 0.0f, 0.0f);
            N.Set(0.0f, 1.0f, 0.0f);
            transIndex = 1.0f;
            hitFront = true;
            normalComputed = false;
        }

        inline const Vector3 & GetTriangleNormal()
        {
            if(!normalComputed){
                N = GetCrossNormal(e1, e2);
                normalComputed = true;
            }
            return N;
        }
        
        inline void UseTriangleNormal()
        {
            N = GetTriangleNormal();
        }
    }HitRecord;

} // namespace AtomTrace

#endif //__ATOMTRACE_HITRECORD_H_
